package shaka.db.internal;

import java.sql.Connection;
import java.sql.SQLException;

import org.sqlite.SQLiteConfig;
import org.sqlite.SQLiteDataSource;

import shaka.db.provider.IConnectionProvider;
import shaka.db.provider.ISqliteProvider;

public class SqliteContainer implements IConnectionProvider {
	private final String alias;
	private SQLiteDataSource ds;

	public SqliteContainer(ISqliteProvider provider) {
		alias = provider.getAlias();
		SQLiteConfig config = new SQLiteConfig();
		config.setSharedCache(true);
		config.enableRecursiveTriggers(true);
		ds = new SQLiteDataSource(config);
		ds.setUrl(String.format("jdbc:sqlite:%s", provider.getDbPath()));
	}

	@Override
	public String getAlias() {
		return alias;
	}

	@Override
	public Connection getConnection() throws SQLException {
		return ds.getConnection();
	}

}
